package com.app.twth.ui.lpnphoto;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.app.twth.app.Constant;
import com.app.twth.base.BaseAndroidViewModel;
import com.app.twth.bean.BaseResponseEntity;
import com.app.twth.bean.LoadingBean;
import com.app.twth.net.JsonCallBack;
import com.app.twth.ui.tally.Tally;
import com.lzy.okgo.model.Response;

import java.util.List;


/**
 * ****************************************************************
 * 文件名称: LoginViewModel
 * 文件描述:
 * 注意事项:
 * 版权声明:
 * ****************************************************************
 */
public class LPNPhotoViewModel extends BaseAndroidViewModel<LPNPhotoDataModel> {

    public MutableLiveData<List<Tally>> putawayContainerLiveData = new MutableLiveData<>();
    public MutableLiveData<List<LPNPhotoDetails>> tallyDetailsLiveData = new MutableLiveData<>();


    public LPNPhotoViewModel(@NonNull Application application) {
        super(application);
    }

    public void getPutawayContainer() {
        isLoading.setValue(new LoadingBean(true, Constant.loading));
        errorResultCode.setValue("");
        mModel.getPutawayContainer(new JsonCallBack<BaseResponseEntity<List<Tally>>>() {
            @Override
            public void onSuccessData(Response<BaseResponseEntity<List<Tally>>> response) {
                isLoading.setValue(new LoadingBean(false, Constant.loading));
                BaseResponseEntity<List<Tally>> baseResponseEntity = response.body();
                if (baseResponseEntity == null) {
                    return;
                }
                if (baseResponseEntity.getCode() == null) {
                    return;
                }
                if (baseResponseEntity.getCode().equals("200")) {
                    putawayContainerLiveData.setValue(baseResponseEntity.data);
                    return;
                }
                infoResultMsg = baseResponseEntity.getMessage();
            }

            @Override
            public void onError(String error) {
                isLoading.setValue(new LoadingBean(false, Constant.loading));
                infoResultMsg = error;
                errorResultCode.setValue(infoResultMsg);
            }
        });
    }

    public void getPutawayDetail(int id) {
        isLoading.setValue(new LoadingBean(true, Constant.loading));
        errorResultCode.setValue("");
        mModel.<List<LPNPhotoDetails>>getPutawayDetail(id, new JsonCallBack<BaseResponseEntity<List<LPNPhotoDetails>>>() {
            @Override
            public void onSuccessData(Response<BaseResponseEntity<List<LPNPhotoDetails>>> response) {
                isLoading.setValue(new LoadingBean(false, Constant.loading));
                BaseResponseEntity<List<LPNPhotoDetails>> baseResponseEntity = response.body();
                if (baseResponseEntity == null) {
                    return;
                }
                if (baseResponseEntity.getCode() == null) {
                    return;
                }
                if (baseResponseEntity.getCode().equals("200")) {
                    tallyDetailsLiveData.setValue(baseResponseEntity.data);
                    return;
                }
                infoResultMsg = baseResponseEntity.getMessage();
            }

            @Override
            public void onError(String error) {
                isLoading.setValue(new LoadingBean(false, Constant.loading));
                infoResultMsg = error;
                errorResultCode.setValue(infoResultMsg);
            }
        });
    }

}
